﻿using FaWorks.WebSite.Models;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FaWorks.WebSite.Hubs
{
    [HubName("userHub")]
    public class UserHub
        : Hub
    {
        public static IHubContext Instance
        {
            get
            {
                return GlobalHost.ConnectionManager.GetHubContext<UserHub>();
            }
        }

        JsonSerializerSettings _settings = new JsonSerializerSettings
        {
            ContractResolver = new CamelCasePropertyNamesContractResolver(),
            NullValueHandling = NullValueHandling.Ignore
        };

        public void Add(User user)
        {
            Clients.All.add(JsonConvert.SerializeObject(user, _settings));
        }

        public void Update(User user)
        {
            Clients.All.update(JsonConvert.SerializeObject(user, _settings));
        }

        public void Remove(User user)
        {
            Clients.All.remove(JsonConvert.SerializeObject(user, _settings));
        }
    }
}